package com.eudon.design_pattern.structural.composite;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicLong;

/**
 * @author eudon
 * @description 目录node
 * @date 2025/9/2
 * @email syd19970616@gmail.com
 * @address <a href="https://gitee.com/eudon">Gitee</a>
 */
public class Directory extends Node {
    private List<Node> children = new ArrayList<>();

    public Directory(String path) {
        super(path);
    }


    void add(Node node) {
        children.add(node);
    }


    void remove(Node node) {
        children.remove(node);
    }

    @Override
    long count() {
        AtomicLong count = new AtomicLong(0);
        children.forEach(node -> count.addAndGet(node.count()));
        return count.get();
    }
}
